Repository navigation
feat(ai-providers): export the shared history-entry renderer - #1758
smart-ssh-coder[bot] wants to merge 5 commits into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated (issue label security; no path from security-paths.txt touched)
Blocking
-
docs/codemap.md:144— The issue's Technical Notes ask for an update to the extension points list (§4 "Extension points"). The entry went into §6 "Large files (more than 2,000 lines)" instead, andprompt_format.rshas 428 lines. §4, the list embedders read, still does not mention the new public functions. The entry also says "the one place … untrusted output is fenced". That claims too much: this file fences only remote command output. Web, extension and sealed content are fenced in core (WebActivity::to_model_text,unavailable_model_text,SealedContent::text_for_model), and the module header correctly says "Remote output". Fix: remove the §6 line and add a §4 entry, e.g. "crates/ai-providers/src/lib.rs—history_entry_text,role_label: render history entries (remote command output fenced) for text-only providers wrapped inTextActionFallback; implemented incrates/ai-providers/src/common/prompt_format.rs." Keep the symbols backticked socheck-codemapchecks them (see the next point). -
crates/ai-providers/src/lib.rs:27-29,prompt_format.rs:9,22-23— Thepub use … as …alias gives one function two names:message_content_text/role_strinside the crate andhistory_entry_text/role_labeloutside it. Three things follow from that:- rustdoc puts the original doc on the re-export, so the public page of
ai_providers::role_labelsays it is "Re-exported asai_providers::role_label". check-codemapcannot resolve the aliases. That is why the last commit removed the backticks, and the public names are no longer checked.- The test compares a function with itself (next point).
Clean shape: rename the two functions in
prompt_format.rstohistory_entry_text/role_label. Update theuselines inanthropic.rs,openai_compatible.rsandopenai_responses.rs, thesee message_content_textcomment and the existing test names. Then re-export with a plainpub use common::prompt_format::{history_entry_text, role_label};and drop the "Re-exported as …" sentences. Also update the stale reference toai_providers::role_strincrates/app-logic/src/compaction.rs:826. This stays within the issue's "thin public re-export" and adds no logic. - rustdoc puts the original doc on the re-export, so the public page of
-
prompt_format.rs:294(test_public_history_entry_text_matches_internal_for_every_variant) — For AC1/AC2 the test says almost nothing:assert_eq!(crate::history_entry_text(c), message_content_text(c))compares the same function with itself.- The test runs inside the crate, so it stays green when the re-export is made
pub(crate). The functional review checked this: the test stays green, while an external caller fails with E0603. - Only the CommandResult variant is pinned to a fixed expected text.
Fix: move the test to the integration tests (
crates/ai-providers/tests/, so the names must be public). For everyMessageContentvariant, assert the output against a fixed expected string, or for the core-rendered variants against the public core function (WebActivity::to_model_text,ExtensionPart::unavailable_model_text,SealedContent::text_for_model,ask_user_model_text). Keep the fence and<security_notice>check for CommandResult and the role mapping for all three roles. -
AC4 ("test covering the default path: the Anthropic/OpenAI request bodies stay byte-identical") — The PR adds no such test.
test_anthropic_and_openai_bodies_render_the_same_command_resultpins one variant's text inside the bodies, not the bodies. The rename above touches the call sites in all three providers, so the criterion now needs real coverage. Add a test that builds the Anthropic and OpenAI (Chat Completions and Responses) request bodies for a history with every variant and role and compares them to the bodies from the base (golden fixture or fixed expected JSON).
Non-blocking
- Commits
2baf4c86anda7486bc5share the message "docs(codemap): reference real symbols for the history renderer". The second one actually removes the symbol markup. Reword them or squash. - Open PRs #1733 and #1743 also touch
docs/codemap.md. There is no conflict now, but one may appear in the same section.
Verified
- AC1 public and documented: the public rustdoc pages for both names exist and carry the "fenced untrusted content … unmodified" text (executed:
cargo doc). An external crate calling both compiles (executed: temporary integration test, removed). - AC2: all 7 variants are covered (read:
crates/core/src/ai/types.rs), but the comparison is tautological. See Blocking. - AC3: no existing test edited, and the crate suite passes (executed).
- requirement "no logic duplicated or changed": the diff only changes visibility and doc comments. All internal call sites use the one implementation (read).
- counter-proof: not a bug fix. A visibility counter-proof was run instead: with
pub(crate) usethe PR test stays green and an external caller fails with E0603 (executed, reverted). - edge cases: binary sealed block → marker only, fail-closed (read). Unsealed extension → fenced placeholder (read). Stdout containing
</stdout>→ escaped by the unchangedformat_command_result(executed: existing test). - callers checked:
message_content_text(5 call sites) → ok.role_str(4) → ok.crates/app-logic/src/compaction.rs:826comment names the never-publicai_providers::role_str(see Blocking, rename). - tests run locally:
cargo test -q -p ai-providers --locked→ 290 + 27 + 37 + 21 passed.cargo clippy -p ai-providers --all-targets --locked -- -D warnings→ clean.cargo fmt --all --check→ ok.node scripts/check-codemap.mjs,node scripts/check-doc-paths.mjs→ ok (all executed). - UI: not a UI change
- data: not touched
- CI: all checks green on
a7486bc5.
Timing analysis
- 1 test file analysed: no timing dependency found (synchronous, deterministic, no I/O).
Coherence
- comments: 3 checked. The codemap entry is misplaced and overclaims, and the "Re-exported as …" doc sentences refer to themselves on the public page. Both are blocking (see above).
- fit: the alias gives one function two names → blocking (in-scope). Clean shape: rename plus plain re-export (see above).
Spec and boundary
- visible behaviour changed: none (library API only, model-facing output unchanged)
- spec searched (fenc, security_notice, untrusted, history), spec covering it: 0039. It describes what is fenced, not where, and is unaffected.
- verdict: not needed. No ADR needed (option A as recommended in the issue). No changelog fragment needed (not user-visible).
- boundary, CI changes, vendor: ok. Public texts are English and edition-neutral. No
.github/changes. The threat-model note "no change – only exposes the existing renderer, no new data flow" holds.
Security checks
- fencing still happens in exactly one place (Spec 0039, invariant 8).
format_command_result/fence_untrusted/format_action_rejectedare unchanged and staypub(crate). No filter, risk or confirmation code is touched. Nothing was loosened against the base. - security review (subagent): 6 bypass attempts (forged closing tags in stdout/stderr, a forged cancel notice, an injected web result tag, an unsealed extension part, ActionResult role spoofing), all blocked by the unchanged renderer → no findings.
UI review
- not a UI change
Follow-ups
- None.
…eir real names, add black-box tests (#1757) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Review points: 1. codemap entry moved to §4, symbols backticked, says 'remote command output' — fixed in 6c75e08. 2. aliases removed, functions renamed, plain |
There was a problem hiding this comment.
Review
Verdict: approved
Review level: elevated (issue label security; no path from security-paths.txt touched)
Blocking
- None.
Non-blocking
crates/ai-providers/src/common/prompt_format.rs:295— the in-crate test is still namedtest_role_str_maps_action_result_to_user, but it now callsrole_label. Last round asked to rename the existing tests too. This is cosmetic: rename it totest_role_label_maps_action_result_to_userthe next time the file is touched.prompt_format.rs:9,:22-23— "Exported asai_providers::…" is true but repeats the item's own name on its public docs page. It could read "Re-exported at the crate root."crates/ai-providers/tests/support/history_fixture.rs:23— theSealedfixture has no content, so the tests pin only the "[content no longer available]" placeholder. That rendering lives in core and this PR does not touch it, so the acceptance criteria do not need more coverage.crates/ai-providers/tests/history_request_bodies.rs— the tests use a wiremock port and a 10 s timeout. A runner withHTTP_PROXYset and noNO_PROXYfor 127.0.0.1 could bypass wiremock. Low risk, and nothing to change on hosted runners.- No changelog fragment: correct. An app user does not notice the change (
changelog.d/README.md), and #1637 shipped without one too.
Verified
- AC1 public and documented: plain
pub use common::prompt_format::{history_entry_text, role_label};, no aliases. The doc comment states the fenced untrusted-content contract (read:crates/ai-providers/src/lib.rs,prompt_format.rs). - AC2:
tests/history_rendering.rschecks all 7MessageContentvariants against fixed expected strings, the full fence and<security_notice>for a command result, and all 3 roles (read; variant list cross-checked againstcrates/core/src/ai/types.rs). Making the exportpub(crate)breaks compilation with E0603 (executed, reverted). - AC3: existing provider tests changed only by the rename this review requested. No assertion changed (read).
- AC4:
tests/history_request_bodies.rssends through the realAnthropicProvider,OpenAiCompatibleProviderandOpenAiResponsesProvideragainst wiremock and comparesmessages/inputwith JSON fixtures. On a cleanorigin/developthe same tests pass, 3 passed (executed: temporary worktree, removed). - counter-proof: with a temporary change to
format_action_rejected, the every-variant test and all 3 body tests fail. WithRole::ActionResult→"assistant", the role test and all 3 body tests fail. Both changes were reverted and everything is green again (executed). - edge cases: same-role grouping (Anthropic/Chat) vs. no grouping (Responses) → pinned, ok. Anthropic
cache_controlon the last message → pinned, ok. Sealed entry with content → not covered (non-blocking). - callers checked:
history_entry_text/role_label(7 uses in 3 providers) → ok.rg 'message_content_text|role_str\b'→ no leftovers in code or docs (executed). - tests run locally:
cargo test -p ai-providers --locked -q→ 289 + 27 + 3 + 3 + 37 + 21 passed.cargo clippy -p ai-providers --all-targets --locked -- -D warnings→ clean.cargo fmt --all --check→ ok.node scripts/check-codemap.mjs,node scripts/check-doc-paths.mjs→ ok (all executed). - UI: not a UI change
- data: not touched
- CI: all checks green on
6c75e08d.
Timing analysis
- 3 test files analysed: no timing dependency in practice.
history_request_bodies.rsuses a 10 s timeout and an ephemeral localhost port; with an empty SSE response there is no retry path → possible, non-blocking. JSON is compared asValue, so key order does not matter.
Coherence
- comments: 4 checked (two doc comments, the
history_entry_textreference inrole_label,compaction.rs:827) → all match the code. The "Exported as …" sentences are true; wording is non-blocking. - fit: the alias is gone, the functions carry their public names and the re-export is plain → the change fits. Stale test name → non-blocking (above).
Spec and boundary
- visible behaviour changed: none (public crate API only; model-facing output pinned unchanged)
- spec searched (history, fenc, untrusted, TextActionFallback, provider), spec covering it: 0039 §3. It describes what is fenced, not where, so it is unaffected.
- verdict: not needed, because behaviour does not change. The ADR 0048 edit only updates a symbol name.
- boundary, CI changes, vendor: ok. Codemap entry now in §4 "Extension points", names the symbols in backticks and says "remote command output fenced". No
.github/changes. "Threat model: no change – only exposes the existing renderer, no new data flow" holds.
Security checks
- Fencing in exactly one place (Spec 0039, invariant 8):
fence_untrustedis still called only inprompt_format.rs.format_command_result/format_action_rejectedstaypub(crate),mod commonstays private. The function bodies are unchanged against the base. No filter, risk, confirmation or credential code is touched, and nothing is loosened. - security review (subagent): 5 bypass attempts (fence-like text in stdout/stderr through the public path, rebuilding a command result without the renderer, direct access to internal formatters, body drift from the rename, public vs. internal variant divergence) → all blocked, no findings.
UI review
- not a UI change
Previous findings
- codemap entry in §6 and overclaiming → fixed in
6c75e08d(§4, backticked symbols, "remote command output") - alias
pub use … as …→ fixed in6c75e08d(functions renamed, plain re-export,compaction.rsand ADR 0048 references updated). One test name left over (non-blocking). - AC2 test tautological / in-crate → fixed in
6c75e08d(black-box tests intests/with fixed expected text) - AC4 missing request-body test → fixed in
6c75e08d(pinned bodies for Anthropic, Chat Completions, Responses; pass on the base)
Follow-ups
- None.
Closes #1757
Summary
ai_providers::history_entry_textandai_providers::role_labelare public. The built-in providers' own functions now carry these names (no aliases), so rustdoc, the codemap checker and callers see one name. Logic is unchanged; the doc comment states the text contains fenced untrusted content and must reach a model unmodified. Codemap entry is in §4 "Extension points".Acceptance Criteria
lib.rspub use, doc on both functions)security_notice, outside the crate: met (crates/ai-providers/tests/history_rendering.rs:test_history_entry_text_renders_every_variant_as_the_providers_do,:test_history_entry_text_keeps_fence_and_notice_for_command_output,:test_role_label_maps_every_role; fixed expected texts, fail to compile if the export ispub(crate))crates/ai-providers/tests/history_request_bodies.rs:test_anthropic_history_body_is_pinned,:test_openai_chat_history_body_is_pinned,:test_openai_responses_history_body_is_pinned; fixtures were checked against a clean checkout ofdevelopand pass there too)cargo test -p ai-providers)Tests
Counter-proof: the rendering test does not compile without the public exports; the body tests pass unchanged on the base, proving no change on that path.
Assumptions
Open question decided: two functions, as recommended.
Spec: none (no behaviour change)
Threat model: no change – only exposes the existing renderer, no new data flow.
Manual test steps: none.
Follow-ups: None.
🤖 Generated with Claude Code